import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {NewsService} from '../news.service';
import {NEWS} from '../newsmodle';

@Component({
    selector: 'app-list',
    templateUrl: './list.component.html',
})
export class ListComponent implements OnInit {

    data: NEWS[] = [];
    total = 0;
    pagesize = 10;
    pageCureent = 1;
    currentType = -1;

    constructor(
        private newsService: NewsService
    ) {
    }

    ngOnInit() {
        this.getlist(this.pageCureent);
    }

    getlist($event) {
        this.newsService.getNewslistByType(String(this.currentType), $event - 1).subscribe((res) => {
            this.data = res['list'];
            this.total = res['totalElement'];
            this.pagesize = res['pageSize'];
            this.pageCureent = $event;
        });
    }

    delnew(item) {
        this.newsService.delNewsById(item.id).subscribe(__ =>
            this.getlist(this.pageCureent)
        );
    }
}
